#!/bin/bash
# -*- coding: utf-8 -*-
#Filename:images_rename.sh
#Author:SuJunQuan
#Email:junquan.su@jwis.cn
#Date:2017-03-11
#Desc:修改镜像名字并上传到镜像仓库,上传完后删除修改名字的镜像,保留原来镜像名称.(此脚本能快速修改镜像名称,并上传到镜像仓库)

#仓库镜像地址
registry_url="192.168.1.205:5000"

#将要上传镜像名称添加到数组里
images=(apiserver socialserver appgateway searchserver marketserver usercenter myprofileserver myprocesserver jcifs serviceassembler windchilladapter)

#遍历数组,根据关键字符修改镜像名称,并上传到指定镜像仓库,上传完后,删除修改镜像,保留原来镜像
for n in `seq ${#images}`
do
    iname=`docker images |grep -w ${images[$n]} |awk '{print $1":"$2}'`
	docker tag $iname $registry_url/$iname
	docker push $registry_url/$iname
    docker rmi $registry_url/$iname
done
